
import {onMounted,watch} from 'vue'
import router from '@/router'
import {ref} from 'vue'
import { useRouter } from 'vue-router';

export default function(){
    const activeIndex=ref("/home");

    watch(  
        () => router.currentRoute.value,  
        (to) => {  
          handleSelect();  
        },  
        { immediate: true } // 立即执行一次以设置初始值  
      );  

    function handleSelect(){
        const path = router.currentRoute.value.path;  
        if (path.startsWith('/problems')) {  
            activeIndex.value = '/problems';  
        }
        if (path.startsWith('/home')) {  
            activeIndex.value = '/home';  
        }
        if (path.startsWith('/test')) {  
            activeIndex.value = '/test';  
        }
        if (path.startsWith('/exam')) {  
            activeIndex.value = '/exam';  
        }
        if (path.startsWith('/class')) {  
            activeIndex.value = '/class';  
        }
    }

    return {activeIndex,handleSelect}
}